#include "tasks.h"
//#include "serial.h"
//#include "core.h"
#include "syscalls.h"

#define BUSYWAIT_COUNTER 100000
#define PINGPONG_PTR ((volatile unsigned char*)0xB0000000)

#define busywait() \
  do { \
      unsigned int i; \
      for (i = 0; i < BUSYWAIT_COUNTER; i++); \
  } while (0)


void 
process_print(int argc, char **argv)
{
    char *s = argc ? argv[0] : "A";
    while (1) {
        printf(s);
        busywait();
    }
}

void 
process_yield(int argc, char **argv)
{
    char *s = argc ? argv[0] : "C";
    while(1) {
       printf(s);
       *((unsigned char*)0x22f30000) = 'C';
       yield();
    }
}

void
process_pingpong(int argc, char **argv)
{
    char processID = argv[0][0];    

    while(1) {
        busywait();
        printf("Prozess '%c' liest %i und schreibt %i...",
                processID,
                *PINGPONG_PTR,
                processID);
        
        *PINGPONG_PTR = processID;
        yield();        
    }
}


